const p1 = new Promise((resolve, reject) => {
    reject(2)
})
const p2 = new Promise((resolve, reject) => {
    resolve(2)
})
Promise.all([p1, p2]).then(res => {
    console.log(res);
})

function myAll (promises) {
    let [count, res] = [0, []]
    return new Promise((resolve, reject) => {
        promises.forEach(item => {
            Promise.resolve(item).then(res1 => {
                count++
                res.push(res1)
                if (count === promises.length) {
                  resolve(res)
                }
            }, err => {
                reject(err)
            })
        })
    })
}
myAll([p1, p2]).then(res => {
    console.log(res);
})